using Assets.Scripts.GDK;
using DG.Tweening;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Brick
{
	public class SelectGuideModule : gdk_base_Imodule
	{
		private List<GameObject> touchMoveNodeList = new List<GameObject>();

		private int touchMoveIndex = -1;

		private bool isTouch;

		private Action<bool> touchEndFun;

		private Action<int> touchMoveFun;

		private Action<Vector2, Vector2> touchMoveLineFun;

		public void setTouchMoveNodeList(List<RectTransform> touchMoveNodeRTList, Action<bool> _touchEndFun, Action<int> _touchMoveFun, Action<Vector2, Vector2> _touchMoveLineFun)
		{
			touchMoveNodeList.Clear();
			for (int i = 0; i < touchMoveNodeRTList.Count; i++)
			{
				RectTransform rectTransform = touchMoveNodeRTList[i];
				touchMoveNodeList.Add(rectTransform.gameObject);
			}
			isTouch = false;
			touchMoveIndex = -1;
			touchEndFun = _touchEndFun;
			touchMoveFun = _touchMoveFun;
			touchMoveLineFun = _touchMoveLineFun;
		}

		private void selectOnGameObject(GameObject gameObject)
		{
			Transform img = gdk_utils.FindChild(gameObject.transform, "Image");
			img.gameObject.SetActive(value: true);
			img.localScale = new Vector2(0f, 0f);
			img.DOScale(1f, 0.25f).SetEase(Ease.Unset).OnComplete(delegate
			{
				img.gameObject.SetActive(value: true);
			});
			Transform transform = gdk_utils.FindChild(gameObject.transform, "textStr");
			transform.GetComponent<Text>().color = new Color(1f, 1f, 1f, 255f);
		}

		private void selectOffGameObject(GameObject gameObject)
		{
			Transform img = gdk_utils.FindChild(gameObject.transform, "Image");
			img.localScale = new Vector2(1f, 1f);
			img.DOScale(0f, 0.25f).SetEase(Ease.Unset).OnComplete(delegate
			{
				img.gameObject.SetActive(value: false);
			});
			Transform transform = gdk_utils.FindChild(gameObject.transform, "textStr");
			transform.GetComponent<Text>().color = new Color(0f, 0f, 0f, 255f);
		}

		private void addGameObject(GameObject gameObject)
		{
			selectOnGameObject(gameObject);
		}

		private void removeGameObject(GameObject gameObject)
		{
			selectOffGameObject(gameObject);
		}

		public void touchStart(GameObject gameObject)
		{
			if (gameObject == touchMoveNodeList[0])
			{
				isTouch = true;
				addGameObject(gameObject);
				touchMoveIndex = 0;
			}
		}

		public void touchMove(GameObject gameObject)
		{
			if (isTouch && touchMoveIndex + 1 == touchMoveNodeList.IndexOf(gameObject))
			{
				touchMoveIndex++;
				addGameObject(gameObject);
				if (touchMoveFun != null)
				{
					touchMoveFun(touchMoveIndex);
				}
			}
		}

		public void touchMove(Vector3 toPos)
		{
			if (isTouch)
			{
				GameObject gameObject = touchMoveNodeList[touchMoveIndex];
				Vector2 arg = gameObject.GetComponent<RectTransform>().localPosition;
				Vector2 arg2 = new Vector2(toPos.x, toPos.y);
				if (touchMoveLineFun != null)
				{
					touchMoveLineFun(arg, arg2);
				}
			}
		}

		public void touchCancel(GameObject gameObject)
		{
			bool obj = false;
			if (touchMoveIndex == touchMoveNodeList.Count - 1)
			{
				obj = true;
			}
			if (touchEndFun != null)
			{
				touchEndFun(obj);
			}
			isTouch = false;
			touchMoveIndex = -1;
			selectOffGameObject(gameObject);
			foreach (GameObject touchMoveNode in touchMoveNodeList)
			{
				selectOffGameObject(touchMoveNode);
			}
		}
	}
}

